unit libAceConfigurarBanco;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ULibFormularioConfirmarCancelarBase, ActnList, ImgList, Buttons,
  StdCtrls, pngimage, jpeg, ExtCtrls, ComCtrls;

type
  TfrmAceConfigurarBanco = class(T_libFormularioConfirmarCancelarBase)
    pcConfig: TPageControl;
    tbsBanco: TTabSheet;
    tbsLogon: TTabSheet;
    gbServidor: TGroupBox;
    edtServidor: TEdit;
    gbBancoDados: TGroupBox;
    edtBancoDados: TEdit;
    gbUsuarioBanco: TGroupBox;
    edtUsuarioBanco: TEdit;
    gbSenhaBanco: TGroupBox;
    edtSenhaBanco: TEdit;
    GroupBox1: TGroupBox;
    edtLogonDominio: TEdit;
    gbBancoDadosCDU: TGroupBox;
    edtBancoDadosCDU: TEdit;
    GroupBox2: TGroupBox;
    edtModoLogon: TEdit;
    procedure FormActivate(Sender: TObject);
    procedure actnConfirmExecute(Sender: TObject);
  private
    { Private declarations }
    procedure SetGUIToIni;
    procedure SetIniToGUI;
  public
    { Public declarations }
  end;

var
  frmAceConfigurarBanco: TfrmAceConfigurarBanco;

implementation

uses
  clsConfig, LibUtils, clsMessageType, Math;

{$R *.dfm}

procedure TfrmAceConfigurarBanco.actnConfirmExecute(Sender: TObject);
begin
  try
    SetGUIToIni;
    Config.Connetion.SaveConnection;
    MessageBoxEx('Dados salvos com sucesso.', mtSucess);
    Self.Close;
  except
    on e: exception do
    begin
      raise exception.Create('Erro ao gravar o arquivo INI.' + #13 +
        'Mensagem Original: ' + e.Message);
    end;
  end;
end;

procedure TfrmAceConfigurarBanco.FormActivate(Sender: TObject);
begin
  inherited;
  pcConfig.ActivePage := tbsBanco;
  SetIniToGUI;
end;

procedure TfrmAceConfigurarBanco.SetGUIToIni;
begin
{$REGION ' Banco de Dados '}
  Config.Connetion.Host := edtServidor.Text;
  Config.Connetion.BancoCDU := edtBancoDadosCDU.Text;
  Config.Connetion.SysDB := edtBancoDados.Text;
  Config.Connetion.User := edtUsuarioBanco.Text;
  Config.Connetion.Password := edtSenhaBanco.Text;
{$ENDREGION}
{$REGION ' Logon '}
  Config.Connetion.Dominio := edtLogonDominio.Text;
  { TODO -oLeonardo -cRefactoring : Alterar pra radioButton }
  Config.Connetion.ModoLogon.AsString := LowerCase(edtModoLogon.Text);
{$ENDREGION}
end;

procedure TfrmAceConfigurarBanco.SetIniToGUI;
begin
{$REGION ' Banco de Dados '}
  edtServidor.Text := Config.Connetion.Host;
  edtBancoDadosCDU.Text := Config.Connetion.BancoCDU;
  edtBancoDados.Text := Config.Connetion.SysDB;
  edtUsuarioBanco.Text := Config.Connetion.User;
  edtSenhaBanco.Text := Config.Connetion.Password;
{$ENDREGION}
{$REGION ' Logon '}
  edtLogonDominio.Text := Config.Connetion.Dominio;
  edtModoLogon.Text := Config.Connetion.ModoLogon.AsString;
{$ENDREGION}
end;

end.
